<?php
	
	include('cms.php');
	
	$idcontent = trim($_POST['idcontent']);
	$rate = trim($_POST['rate']);
	$ip = $_SERVER['REMOTE_ADDR'];
	
	
	//Insert Rate quickly
	DataLatte::update("INSERT INTO cmsRate(cmsContent_idcontent, ip, time, rate) VALUES('$idcontent', '$ip', NOW(), '$rate')");
	
	//Update content's rating
	DataLatte::update("UPDATE cmsContent SET rating = (SELECT AVG(rate) FROM cmsRate WHERE cmsContent_idcontent = '$idcontent') WHERE idcontent = '$idcontent'");

	echo 'OK';
?>